import 'package:flutter/widgets.dart';

class GLCategoryModel {
  late String id;
  late String title;
  late String color;
  late Color cColor;

  GLCategoryModel({required this.id, required this.title, required this.color});

  GLCategoryModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];
    color = json['color'];
    // 1. 将 color 转换成 16 进制数字
    final colorInt = int.parse(color, radix: 16);
    // 2. 添加透明度
    cColor = Color(colorInt | 0xFF000000);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['title'] = this.title;
    data['color'] = this.color;
    data['cColor'] = this.cColor;
    return data;
  }
}